//
//  YHEmoticonPageView.swift
//  YHWeibo
//
//  Created by yuhao.mac on 16/7/4.
//  Copyright © 2016年 yuhao.mac. All rights reserved.
//

import UIKit

private let YHEmoticonPageViewCellId = "EmoticonPageViewCellId"

class YHEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    @objc private func setupUI(){
        backgroundColor = RandomColor()
        //注册cell
        registerClass(YHEmoticonPageViewCell .self, forCellWithReuseIdentifier: YHEmoticonPageViewCellId)
        
        dataSource = self
        let layout = collectionViewLayout as! UICollectionViewFlowLayout
        
        layout.itemSize = CGSize(width: SCREENW, height: 216 -  37)
        
        layout.minimumInteritemSpacing = 0
        layout.minimumLineSpacing = 0
        
        layout.scrollDirection = .Horizontal
        
    }

}

extension YHEmoticonPageView:UICollectionViewDataSource {
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
        return YHEmotcionTools.sharedTools.allEmoticons.count
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return YHEmotcionTools.sharedTools.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(YHEmoticonPageViewCellId, forIndexPath: indexPath) as! YHEmoticonPageViewCell
        
        cell.indexPath = indexPath
        
        cell.emoticons = YHEmotcionTools.sharedTools.allEmoticons[indexPath.section][indexPath.item]
        
        return cell
    }
}





